﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using YT.Commons;

namespace YT.XH.MF
{
    public partial class frmMExportToExcelSel : Form
    {
        private string mstrType = string.Empty;
        private TitleType mType = new TitleType();
        private bool mblnSave = false;
        private DB.DBAccess mdbcon = null;
        public frmMExportToExcelSel()
        {
            InitializeComponent();
        }

        private string strGetTypeString( TitleType mType )
        {
            if (mType == TitleType.Dizziness)
            {
                return "300";
            }
            else if (mType == TitleType.MeniereDisease)
            {
                return "100";
            }
            else if (mType == TitleType.NOSE)
            {
                return "400";
            }
            else if (mType == TitleType.OTHERS)
            {
                return "500";
            }
            else if (mType == TitleType.SuddenDeafness)
            {
                return "200";
            }
            return "";
        }
        
        private string GetstrTypeFromMenuType(TitleType mType)
        {
            if (mType == TitleType.MeniereDisease  )
            {
                return "MeniereDisease";
            }
            else if ( mType == TitleType.SuddenDeafness  )
            {
                return "SuddenDeafness";
            }
            else if ( mType == TitleType.Dizziness  )
            {
                return "Dizziness";
            }
            else if ( mType == TitleType.NOSE  )
            {
                return "NOSE";
            }
            else if ( mType == TitleType.OTHERS)
            {
                return "Others";
            }
            return "";
        }

        public string strGetExportSQL( TitleType type , DB.DBAccess dbcon )
        {
            mType = type;
            mdbcon = dbcon;
            FillFormSel();
            this.ShowDialog();
            return strReturn();
        }

        private void FillFormSel()
        {
            chkFormSel.Items.Clear(); 
            if (mType == TitleType.SuddenDeafness)
            {
                chkFormSel.Items.Add("病史调查");
                chkFormSel.Items.Add("治疗前检查"); 
                
                chkFormSel.Items.Add("疗效评估_7天");
                chkFormSel.Items.Add("疗效评估_14天");
                chkFormSel.Items.Add("疗效评估_28天");

                chkFormSel.Items.Add("更多评估");

                chkFormSel.Items.Add("治疗结束后综合疗效评估");
                chkFormSel.Items.Add("不良反应报告");
            }
            if (mType == TitleType.Dizziness)
            {
                chkFormSel.Items.Add("病史调查");
                chkFormSel.Items.Add("治疗前检查");
                chkFormSel.Items.Add("第1周");
                chkFormSel.Items.Add("第2周");
                chkFormSel.Items.Add("第1月");
                chkFormSel.Items.Add("第3月");
                chkFormSel.Items.Add("第6月");
                chkFormSel.Items.Add("不良反应报告");
            }
            if (mType == TitleType.MeniereDisease)
            {
                chkFormSel.Items.Add("病史调查");
                chkFormSel.Items.Add("治疗前检查");

                chkFormSel.Items.Add("急性期 疗效评估");       
                chkFormSel.Items.Add("间歇期 疗效评估 第1月") ;
                chkFormSel.Items.Add("间歇期 疗效评估 第3月");
                chkFormSel.Items.Add("间歇期 疗效评估 第6月") ;
                chkFormSel.Items.Add("间歇期 疗效评估 第12月");
                chkFormSel.Items.Add("间歇期 疗效评估 第24月");

                chkFormSel.Items.Add("其它非中耳给药治疗观察期 确诊病例 疗效评估");
                chkFormSel.Items.Add("其它非中耳给药治疗观察期 待诊病例 疗效评估");
            }

        }

        private string GetTableName(TitleType type, string strMenuName)
        {
            if (type == TitleType.SuddenDeafness)
            {
                if (strMenuName == "病史调查") return "titleResult";
                if (strMenuName == "治疗前检查") return "ExamBeforTreatResult";

                if (strMenuName == "更多评估") return "TreatmentEffectResult";
                if (strMenuName == "疗效评估_7天") return "TreatmentEffectResult";
                if (strMenuName == "疗效评估_14天") return "TreatmentEffectResult";
                if (strMenuName == "疗效评估_28天") return "TreatmentEffectResult";
                if (strMenuName == "不良反应报告") return "UntowardEffectResult";
                if (strMenuName == "治疗结束后综合疗效评估") return "EffectAfterTreateResult";
                return "";
            }
            else if ( type == TitleType.Dizziness)
            {

                if (strMenuName == "病史调查") return "titleResult";
                if (strMenuName == "治疗前检查") return "ExamBeforTreatResult";
                if (strMenuName == "第1周") return "TreatmentEffectResult";
                if (strMenuName == "第2周") return "TreatmentEffectResult";
                if (strMenuName == "第1月") return "TreatmentEffectResult";
                if (strMenuName == "第3月") return "TreatmentEffectResult";
                if (strMenuName == "第6月") return "TreatmentEffectResult";
                if (strMenuName == "不良反应报告") return "UntowardEffectResult";                
            }
            else if (type == TitleType.MeniereDisease)
            {
                if (strMenuName == "病史调查") return "titleResult";
                if (strMenuName == "治疗前检查") return "ExamBeforTreatResult";
                
                if (strMenuName == "急性期 疗效评估") return "TreatmentEffectResult_Emergency";

                if (strMenuName == "间歇期 疗效评估 第1月") return "TreatmentEffectResult";
                if (strMenuName == "间歇期 疗效评估 第3月") return "TreatmentEffectResult";
                if (strMenuName == "间歇期 疗效评估 第6月") return "TreatmentEffectResult";
                if (strMenuName == "间歇期 疗效评估 第12月") return "TreatmentEffectResult";
                if (strMenuName == "间歇期 疗效评估 第24月") return "TreatmentEffectResult";

                if (strMenuName == "其它非中耳给药治疗观察期 确诊病例 疗效评估") return "TreatmentEffectResult_Sure";
                if (strMenuName == "其它非中耳给药治疗观察期 待诊病例 疗效评估") return "TreatmentEffectResult_Watch";
                if (strMenuName == "不良反应报告") return "UntowardEffectResult";       
            }
            else
            {
                return "";
            }
            return "";
        }

        private string ReturnExportSQL( TitleType type,string strMenuName )
        {
            string strmSickPersonSQL = "select A.sickrecid as 系统编号,SickID as 编号,SickName as 姓名,Birth as 出生日期 ,Sex as 性别,A.ExamSeqNo as 序号,";
            string strSQL = "";
            if (type == TitleType.SuddenDeafness)
            {
                #region 突聋
               
                if (strMenuName == "治疗前检查" )
                {
                    strSQL = strmSickPersonSQL;
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmSDExamBeforeTreatTitle");
                    strSQL += " from ExamBeforTreatResult A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "' and A.ExamSeqNo=1 ";
                    strSQL += " group by a.sickrecid,a.examseqno,SickID,SickName,Birth,Sex,A.ExamSeqNo ";
                }
                else if (strMenuName == "疗效评估_7天" )
                {
                    strSQL = strmSickPersonSQL;
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmSDTreatmentEffectTitle");
                    strSQL += " from TreatmentEffectResult A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "' and A.ExamSeqNo=1 ";
                    strSQL += " group by a.sickrecid,a.examseqno,SickID,SickName,Birth,Sex,A.ExamSeqNo ";
                }
                else if (strMenuName == "疗效评估_14天")
                {
                    strSQL = strmSickPersonSQL;
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmSDTreatmentEffectTitle");
                    strSQL += " from TreatmentEffectResult A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "' and A.ExamSeqNo=2 ";
                    strSQL += " group by a.sickrecid,a.examseqno,SickID,SickName,Birth,Sex,A.ExamSeqNo ";
                }
                else if (strMenuName == "疗效评估_28天")
                {
                    strSQL = strmSickPersonSQL;
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmSDTreatmentEffectTitle");
                    strSQL += " from TreatmentEffectResult A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "' and A.ExamSeqNo=3 ";
                    strSQL += " group by a.sickrecid,a.examseqno,SickID,SickName,Birth,Sex,A.ExamSeqNo ";
                }
                else if (strMenuName == "更多评估")
                {
                    strSQL = strmSickPersonSQL;
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmSDTreatmentEffectTitle");
                    strSQL += " from TreatmentEffectResult A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "' and A.ExamSeqNo>=4 ";
                    strSQL += " group by a.sickrecid,a.examseqno,SickID,SickName,Birth,Sex,A.ExamSeqNo ";
                }
                #endregion
            }
            else if (type == TitleType.Dizziness)
            {
                #region 良性阵发性位置性眩晕
                if (strMenuName=="病史调查")
                {
                    strSQL = @"select A.sickrecid as 系统编号,SickID as 编号,SickName as 姓名,Birth as 出生日期 ,Sex as 性别,";
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmDZSickHistory");
                    strSQL += " from " + GetTableName(mType, strMenuName) + " A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "' ";
                    strSQL += " group by a.sickrecid,SickID,SickName,Birth,sex";
                }
                else if (strMenuName == "治疗前检查")
                {
                    strSQL = @"select A.sickrecid as 系统编号,SickID as 编号,SickName as 姓名,Birth as 出生日期 ,Sex as 性别,";
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmDZExamBeforeTreatTitle");
                    strSQL += " from ExamBeforTreatResult A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "' and A.ExamSeqNo=1 ";
                    strSQL += " group by a.sickrecid,a.examseqno,SickID,SickName,Birth,Sex,A.ExamSeqNo ";
                }
                else if (strMenuName == "第1周")
                {
                    strSQL = strmSickPersonSQL;
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmDZTreatmentEffectTitle");
                    strSQL += " from TreatmentEffectResult A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "' and A.ExamSeqNo=1 ";
                    strSQL += " group by a.sickrecid,a.examseqno,SickID,SickName,Birth,Sex,A.ExamSeqNo ";
                }             
                if (strMenuName == "第2周")
                {
                    strSQL = strmSickPersonSQL;
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmDZTreatmentEffectTitle");
                    strSQL += " from TreatmentEffectResult A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "' and A.ExamSeqNo=2 ";
                    strSQL += " group by a.sickrecid,a.examseqno,SickID,SickName,Birth,Sex,A.ExamSeqNo ";

                }
                if (strMenuName == "第1月") 
                {
                    strSQL = strmSickPersonSQL;
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmDZTreatmentEffectTitle");
                    strSQL += " from TreatmentEffectResult A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "' and A.ExamSeqNo=3 ";
                    strSQL += " group by a.sickrecid,a.examseqno,SickID,SickName,Birth,Sex,A.ExamSeqNo ";
                }
                if (strMenuName == "第3月") 
                {
                    strSQL = strmSickPersonSQL;
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmDZTreatmentEffectTitle");
                    strSQL += " from TreatmentEffectResult A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "' and A.ExamSeqNo=4 ";
                    strSQL += " group by a.sickrecid,a.examseqno,SickID,SickName,Birth,Sex,A.ExamSeqNo ";
                }
                if (strMenuName == "第6月")
                {
                    strSQL = strmSickPersonSQL;
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmDZTreatmentEffectTitle");
                    strSQL += " from TreatmentEffectResult A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "' and A.ExamSeqNo=5 ";
                    strSQL += " group by a.sickrecid,a.examseqno,SickID,SickName,Birth,Sex,A.ExamSeqNo ";
                }
                if (strMenuName == "不良反应报告")
                {
                    strSQL = @"select A.sickrecid as 系统编号,SickID as 编号,SickName as 姓名,Birth as 出生日期 ,Sex as 性别,";
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmDZUntowardEffectTitle");
                    strSQL += " from " + GetTableName(mType, strMenuName) + " A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "'    ";
                    strSQL += " group by a.sickrecid,SickID,SickName,Birth,sex";
                }
                #endregion
            }
            else if (type == TitleType.MeniereDisease)
            {
                if (strMenuName == "急性期 疗效评估") // return "TreatmentEffectResult_Emergency";
                {
                    strSQL = strmSickPersonSQL;
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmMDTreatmentEffectTitle_Hurry");
                    strSQL += " from TreatmentEffectResult_Emergency A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "' ";
                    strSQL += " group by a.sickrecid,a.examseqno,SickID,SickName,Birth,Sex,A.ExamSeqNo ";
                }
                else if (strMenuName == "治疗前检查")  //frmMDExamBeforeTreatTitle
                {
                    strSQL = @"select A.sickrecid as 系统编号,SickID as 编号,SickName as 姓名,Birth as 出生日期 ,Sex as 性别,";
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmMDExamBeforeTreatTitle");
                    strSQL += " from " + GetTableName(mType, strMenuName) + " A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "'    ";
                    strSQL += " group by a.sickrecid,SickID,SickName,Birth,sex";
                }
                else if (strMenuName == "间歇期 疗效评估 第1月") //return "TreatmentEffectResult";
                {
                    strSQL = strmSickPersonSQL;
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmMDTreatmentEffectTitle");
                    strSQL += " from TreatmentEffectResult A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "' and A.ExamSeqNo=1 ";
                    strSQL += " group by a.sickrecid,a.examseqno,SickID,SickName,Birth,Sex,A.ExamSeqNo ";
                }
                else if (strMenuName == "间歇期 疗效评估 第3月") //return "TreatmentEffectResult";
                {

                    strSQL = strmSickPersonSQL;
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmMDTreatmentEffectTitle");
                    strSQL += " from TreatmentEffectResult A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "' and A.ExamSeqNo=2 ";
                    strSQL += " group by a.sickrecid,a.examseqno,SickID,SickName,Birth,Sex,A.ExamSeqNo ";

                }
                else if (strMenuName == "间歇期 疗效评估 第6月") //return "TreatmentEffectResult";
                {
                    strSQL = strmSickPersonSQL;
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmMDTreatmentEffectTitle");
                    strSQL += " from TreatmentEffectResult A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "' and A.ExamSeqNo=3   ";
                    strSQL += " group by a.sickrecid,a.examseqno,SickID,SickName,Birth,Sex,A.ExamSeqNo ";
                }
                else if (strMenuName == "间歇期 疗效评估 第12月") //return "TreatmentEffectResult";
                {
                    strSQL = strmSickPersonSQL;
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmMDTreatmentEffectTitle");
                    strSQL += " from TreatmentEffectResult A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "' and A.ExamSeqNo=4   ";
                    strSQL += " group by a.sickrecid,a.examseqno,SickID,SickName,Birth,Sex,A.ExamSeqNo ";
                }
                else if (strMenuName == "间歇期 疗效评估 第24月") //return "TreatmentEffectResult";
                {
                    strSQL = strmSickPersonSQL;
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmMDTreatmentEffectTitle");
                    strSQL += " from TreatmentEffectResult A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "' and A.ExamSeqNo=5   ";
                    strSQL += " group by a.sickrecid,a.examseqno,SickID,SickName,Birth,Sex,A.ExamSeqNo ";
                }

                else if (strMenuName == "其它非中耳给药治疗观察期 确诊病例 疗效评估") //return "TreatmentEffectResult_Sure";
                {
                    strSQL = strmSickPersonSQL;
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmMDTreatmentEffectTitle_Sure");
                    strSQL += " from TreatmentEffectResult_Sure A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "'   ";
                    strSQL += " group by a.sickrecid,a.examseqno,SickID,SickName,Birth,Sex,A.ExamSeqNo ";
                }
                else if (strMenuName == "其它非中耳给药治疗观察期 待诊病例 疗效评估") //return "TreatmentEffectResult_Watch";
                {
                    strSQL = strmSickPersonSQL;
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmMDTreatmentEffectTitle_Watch");
                    strSQL += " from TreatmentEffectResult_Watch A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "'    ";
                    strSQL += " group by a.sickrecid,a.examseqno,SickID,SickName,Birth,Sex,A.ExamSeqNo ";
                }
                else
                {
                    strSQL = @"select A.sickrecid as 系统编号,SickID as 编号,SickName as 姓名,Birth as 出生日期 ,Sex as 性别,";
                    strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmSickHistory");
                    strSQL += " from " + GetTableName(mType, strMenuName) + " A ";
                    strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                    strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "'    ";
                    strSQL += " group by a.sickrecid,SickID,SickName,Birth,sex";
                }

            }
            if ( strSQL =="")
            {
                strSQL = @"select A.sickrecid as 系统编号,SickID as 编号,SickName as 姓名,Birth as 出生日期 ,Sex as 性别,";
                strSQL += BaseFunctions.GetExportLineSQL(GetstrTypeFromMenuType(mType), strMenuName, "frmSDSickHistory");
                strSQL += " from " + GetTableName(mType, strMenuName) + " A ";
                strSQL += " right join ( select * from mSickPerson where type='" + GetstrTypeFromMenuType(mType) + "') C  on A.SickRecID=C.SickRecID ";
                strSQL += " and A.Type='" + GetstrTypeFromMenuType(mType) + "' ";
                strSQL += " group by a.sickrecid,SickID,SickName,Birth,sex";
            }
            return strSQL;
        }

        private string strReturn()
        {
            string strSQL = "";
            for (int i = 0; i <= this.chkFormSel.CheckedItems.Count - 1; i++)
            {

                strSQL += "\r\n" + ReturnExportSQL(mType, this.chkFormSel.CheckedItems[i].ToString ());
            }
            return strSQL ;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            mblnSave = true;
            this.Close(); 
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            mblnSave = false ;
            this.Close(); 
        }



    }
}
